package com.ruoyi.information.service.impl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.information.domain.Information;
import com.ruoyi.information.mapper.InformationMapper;
import com.ruoyi.information.service.InformationService;
import com.ruoyi.procurement.domain.ProcurementModel;
import com.ruoyi.procurement.domain.ProcurementOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class InformationServiceImpl implements InformationService {

    @Autowired
    public InformationMapper informationMapper;

    /**
     * 查询资料列表
     *
     * @param map 查询条件
     * @return 结果
     */
    @Override
    public Information selectInformationByMap(Map map) {
        return informationMapper.selectInformationByMap(map);
    }

    /**
     * 修改产品资料列表
     *
     * @param procurementOrder 产品资料信息
     * @return 结果
     */
    @Override
    public int updateInformationList(ProcurementOrder procurementOrder) {
        SysUser sysUser= SecurityUtils.getLoginUser().getUser();
        List<ProcurementModel> procurementModelList = procurementOrder.getProcurementModelList();
        List<Information> list = new ArrayList<>();
        for (ProcurementModel procurementModel : procurementModelList) {
            Information information = new Information();
            information.setInformationId(procurementModel.getInformationId());
            information.setModelCode(procurementModel.getModelCode());
            information.setDeptId(sysUser.getCompanyId());
            information.setProductType(procurementModel.getProductType());
            information.setBatch(procurementModel.getBatch());
            information.setDisinfectName(procurementModel.getDisinfectName());
            information.setDisinfectAddress(procurementModel.getDisinfectAddress());
            information.setFactoryInspectionName(procurementModel.getFactoryInspectionName());
            information.setFactoryInspectionAddress(procurementModel.getFactoryInspectionAddress());
            information.setNucleicAcidName(procurementModel.getNucleicAcidName());
            information.setNucleicAcidAddress(procurementModel.getNucleicAcidAddress());
            information.setCustomsName(procurementModel.getCustomsName());
            information.setCustomsAddress(procurementModel.getCustomsAddress());
            information.setCommodityName(procurementModel.getCommodityName());
            information.setCommodityAddress(procurementModel.getCommodityAddress());
            list.add(information);
        }
        return informationMapper.updateInformationList(list);
    }

    @Override
    public List<Information> selectInformationByList(List<Map> maps) {
        return informationMapper.selectInformationByList(maps);
    }
}
